class EventsSweeper < ActionController::Caching::Sweeper
  observe Event
  
	def after_update(event)
		expire_cache_for(event)
	end
	
	def after_destroy(event)
		expire_cache_for(event)
	end
	
  def after_events_add_attendee
    expire_cache_for(assigns(:event))
  end
  
  def after_events_update_attendees
    expire_cache_for(assigns(:event))
  end
  
  def after_events_remove
    expire_cache_for(assigns(:event))
  end
  
  def after_events_undelete
    expire_cache_for(assigns(:event))
  end
  
  def after_events_add_current_user
    expire_cache_for(assigns(:event))
  end
  
  def after_events_remove_attendee
    expire_cache_for(assigns(:event))
  end
  
  def after_events_submit_attendee_hours
    expire_cache_for(assigns(:event))
  end
  
  def after_events_do_replace
    expire_cache_for(assigns(:event))
  end
  
  def after_events_un_approve_event
    expire_cache
  end
  
	private
	def expire_cache_for(event)
    # caller[0]=~/`(.*?)'/  # note the first quote is a backtick
    # puts $1 + " events"
	  expire_cache unless !event.approved
	end
	
  def expire_cache
    expire_fragment(%r(members/list\?action_suffix=list_.*))
    # caller[0]=~/`(.*?)'/  # note the first quote is a backtick
    # message = $1
    # puts message + " events" unless message == "expire_cache_for"
    end
end
